﻿@model ADZ_HuodongMaster
@{
    ViewBag.Title = "活动编辑";
    Layout = "~/Views/Shared/_ContentLayout.cshtml";

    var viewModel = Model ?? new ADZ_HuodongMaster();
    ADZ_MasterEntities dbcontext = new ADZ_MasterEntities();
    Dictionary<string, string> dc = new Dictionary<string, string>();
}

<form id="S_Form" action="@Url.Action("add", "huodong")" method="post" class="definewidth m20" enctype="multipart/form-data">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td colspan="4" style="width:50%">
                <h5>@ViewBag.Title @(viewModel.huodong_id > 0 ? "活动编号：" + viewModel.huodong_id : "")</h5>
                <input type="hidden" value="@viewModel.huodong_id" name="huodong_id" id="huodong_id" />
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">活动图片<em>*</em></td>
            <td colspan="3">

                @{
                    OneImgModel oneImgModel = new OneImgModel();
                    oneImgModel.img_url = Model.img_url;
                    oneImgModel.showdel = true;
                    oneImgModel.remark = "设置活动图片";
                    Html.RenderPartial(Url.Content("~/Views/Common/ImgsOneCommon.cshtml"), oneImgModel);
                }
            </td>
        </tr>
        <tr>
            <td width="6%" class="tableleft">活动标题<em>*</em></td>
            <td>
                <input type="text" name="huodong_title" style="width:300px;" value="@Model.huodong_title" />
            </td>
            <td width="6%" class="tableleft">活动状态<em>*</em></td>
            <td>
                <input type="radio" name="huodong_status" style="vertical-align:middle; margin-bottom:6px;" value="@((int)HuodongStatus.Default)" />未开始
                <input type="radio" name="huodong_status" style="vertical-align:middle; margin-bottom:6px;" value="@((int)HuodongStatus.InProgress)" />进行中
                <input type="radio" name="huodong_status" style="vertical-align:middle; margin-bottom:6px;" value="@((int)HuodongStatus.Finished)" />已结束
            </td>
        </tr>
        <tr>
            <td class="tableleft">开始时间<em>*</em></td>

            <td>
                <input type="text" name="begin_time" style="width:160px;" class="calendar calendar-time" maxlength="50" value="@Model.begin_time.ToString(1)" />
            </td>
            <td class="tableleft">结束时间<em>*</em></td>

            <td>
                <input type="text" name="end_time" style="width:160px;" class="calendar calendar-time" maxlength="50" value="@Model.end_time.ToString(1)" />
            </td>

        </tr>
        <tr>
            <td class="tableleft">内容描述</td>
            <td colspan="3"><textarea name="huodong_content" style="width:80%;" maxlength="550" cols="4">@Model.huodong_content</textarea></td>
        </tr>

        <tr>
            <td class="tableleft"></td>
            <td colspan="3">
                <p><span id="spMsg"></span></p>
                <button type="submit" class="btn btn-primary">保存</button> &nbsp;&nbsp;

                <button type="button" backpageid="huodong/getlist" class="btn btn-success" name="backid" id="backid">返回列表</button>
            </td>
        </tr>
    </table>
    @if (viewModel.huodong_id > 0)
    {
        <h5>商品列表  <a href="/huodong/editgoods?huodong_id=@viewModel.huodong_id">编辑商品信息</a></h5>
        <table class="table table-bordered table-hover definewidth m10">
            <thead>
                <tr>
                    <th style="width:70px">图片</th>
                    <th>料号</th>
                    <th>品牌</th>
                    <th>分类</th>
                    <th>供应商</th>
                    <th>DC号</th>
                    <th>上架时间</th>
                    <th>是否上架</th>
                    <th>是否含税</th>
                    <th>库存数量</th>
                    <th>备注</th>
                    <th></th>
                </tr>
            </thead>
            @{
                var goods_ids =
                    from t in dbcontext.ADZ_GoodsHuodong
                    where t.huodong_id.Equals(viewModel.huodong_id)
                    select t.goods_id;

                var good_list = dbcontext.Views_Goods.Where(t => goods_ids.Contains(t.goods_id) && t.is_del == 0);

                int index = 0;
                foreach (var m in good_list)
                {
                    index++;
                    <tr class="@HtmlPagerHelper.TrClass(index)">
                        <td>
                            @{
                                var aDZ_GoodsIMGs = dbcontext.ADZ_GoodsIMG.Where(t => t.goods_id == m.goods_id);
                                foreach (var item in aDZ_GoodsIMGs.OrderBy(t => t.sort_NO))
                                {
                                    <a href="@ImageFileBiz.GetImg(item.img_url)" target="_blank"> <img style="width:30px;margin:1px 1px 1px 1px;" src="@ImageFileBiz.GetImg(item.img_url,"small")" /></a>
                                }
                            }
                        </td>
                        <td>@m.MPN</td>
                        <td>@m.brand_name</td>
                        <td>@m.category_name</td>
                        <td>@m.supplier_name</td>
                        <td>@m.DCN</td>
                        <td>@m.with_up_time.ToString(1)</td>
                        <td>
                            @if (m.is_withdraw == 0)
                            {
                            <info class="green">已上架</info>
                            }
                            else if (m.is_withdraw == 1)
                            {
                            <info class="red">已下架</info>
                            }
                        </td>
                        <td>
                            @if (m.include_tax == 0)
                            {
                                <info>未含税</info>
                            }
                            else if (m.include_tax == 1)
                            {
                                <info class="green">含税</info>
                            }
                        </td>
                        <td>@m.stock_amount @m.goods_unit</td>
                        <td>@m.product_desc</td>
                        <td>
                            <a href="@Url.Action("detailInfo", "product", new { id = m.goods_id})">查看</a>
                        </td>
                    </tr>
                }
            }
        </table>
    }



    <script>
        BUI.use('bui/overlay', function (overlay) {
            $(function () {
                switch ('@Model.huodong_status') {
                    case '0':
                        $("input[name='huodong_status']").get(0).checked = true;
                        break;
                    case '1':
                        $("input[name='huodong_status']").get(1).checked = true;
                        break;
                    case '2':
                        $("input[name='huodong_status']").get(2).checked = true;
                        break;
                }

                var validator = $('form').validate({
                    errorLabelContainer: $("#errorContainer"),
                    errorElement: "span",
                    rules: {
                        img_url: { required: true },
                        huodong_status: { required: true },
                        begin_time: { required: true },
                        huodong_title: { required: true }
                    },
                    submitHandler: function (form) {
                        $(form).ajaxSubmit(function (result) {
                            ShowActionResult(result, function () { self.location = document.referrer; });
                        });
                    }
                });

            });
        });
    </script>
</form>
